//LiteLoaderScript Dev Helper
/// <reference path="e:\vsCodePlugins\mcide/Library/JS/Api.js" /> 


/* 
插件名:LXLRobot
作者:Yoyo
QQ:1294858802
E-mail:1294858802@qq.com
版本: v0.0.4
介绍:这个是一个纯LXL插件的机器人 对接 Mirai机器人框架的HTTPAPI插件 !
功能介绍:
websocket 处理
事件函数封装
api函数封装
plugins插件扩展功能
各种疑惑:解答
问:作者文凭?  答:我小学都特么没有毕业! 
问:这个插件有啥用 ?  答:主要用于对接 Mirai机器人框架的HTTPAPI插件  来实现机器人互通 (可以保证控制台干净整洁!而且支持扩展,扩展除了本插件提供的事件和api  LXL加载器的都支持)
问:为啥要用这个插件呢?  答:这个插件 就是单纯的一个框架  具体功能 需要通过 扩展来实现! (没人强迫您!)
问:作者一个月多少k?  答:我在养老等死,工厂打螺丝!(怎么?你要赞助我吗?)
*/


const ROBOTCONFIG = new JsonConfigFile(".\\plugins\\Yoyo\\LXLRobot\\config.json", JSON.stringify({
    verifyKey: "1234567890",
    port: 55555,
    host: "127.0.0.1",
    qq: "1536724751"
}));
const ROBOTQQ = ROBOTCONFIG.get("qq");
logger.setConsole(true);
logger.setTitle("LXLRobot");
class websocket {
    #socket;
    #status = false;
    #connectTimeCode = null;
    sessionKey = null;
    constructor() {
        this.#socket = new WSClient();
        this.#socket.listen("onTextReceived", (msg) => { this.onTextReceived(msg); });//收到文本消息
        this.#socket.listen("onLostConnection", (code) => { this.onLostConnection(code); });//连接关闭
        this.#socket.listen("onError", (msg) => { this.onError(msg); });//发生错误
        this.connect();

    }

    connect() {//创建连接
        if (this.#connectTimeCode) clearInterval(this.#connectTimeCode);
        this.#status = this.#socket.connect(`ws://${ROBOTCONFIG.get("host")}:${ROBOTCONFIG.get("port")}/all?verifyKey=${ROBOTCONFIG.get("verifyKey")}&qq=${ROBOTQQ}`);
        if (!this.#status) {
            logger.warn("连接失败5秒后再次尝试!");
            this.#connectTimeCode = setTimeout(() => { this.connect(); }, 5000);
        } else {
            this.#socket.send("ping:HeartRateResponse");
            logger.info("websocket连接成功,事件功能运行中!");
        }
    }
    onTextReceived(msg) {//收到文本消息
        let isJson = this.isJSON(msg);
        if (isJson) {
            let jsonObj = JSON.parse(msg);
            if (jsonObj.code != 400) {
                //记录
                if (typeof jsonObj.data.code != "undefined" && typeof jsonObj.data.session != "undefined") {
                    this.sessionKey = jsonObj.data.session;
                    //加载插件扩展
                     PluginsClass.loadPluginsAll();
                }
                // sessionKey
                //消息和事件分支
                switch (jsonObj.data.type) {
                    case "FriendMessage":
                        RobotEventClass.onChumMessage(jsonObj);//好友
                        break;
                    case "TempMessage":
                        RobotEventClass.onTempMessage(jsonObj);//临时私聊我
                        break;
                    case "GroupMessage":
                        RobotEventClass.onGroupMessage(jsonObj);//群
                        break;
                    case "MemberJoinRequestEvent":
                        RobotEventClass.onMemberJoinRequestEvent(jsonObj);//申请入群
                        break;
                    case "MemberJoinEvent":
                        RobotEventClass.onMemberJoinEvent(jsonObj);//成员加入群
                        break;    
                    case "MemberMuteEvent":
                        RobotEventClass.onMemberMuteEvent(jsonObj);//成员被禁言
                        break;
                    case "MemberLeaveEventKick":
                        RobotEventClass.onMemberLeaveEventKick(jsonObj);//成员被踢出群
                        break;
                    case "MemberLeaveEventQuit":
                        RobotEventClass.onMemberLeaveEventQuit(jsonObj);//成员主动退群
                        break;
                }
            }
        }


    }

    onLostConnection(code) {//连接关闭
        this.#status = false;
        logger.info("连接被关闭5秒后再次请求!关闭代码:" + code+"| 请检查密钥|机器人qq号是否正确");
        setTimeout(()=>{this.connect();},5000);
    }

    onError(msg) {
        logger.error("发生错误!");
    }


    isJSON(str) {
        if (typeof str == 'string') {
            try {
                var obj = JSON.parse(str);
                if (typeof obj == 'object' && obj) {
                    return true;
                } else {
                    return false;
                }

            } catch (e) {
                return false;
            }
        }
    }

    sendMsg(msg) {
        this.#socket.send(msg);
    }
}

//机器人事件

class RobotEvent {
    #Event = {};
    constructor() { }
    /* 注册事件 */
    regEvent(type,func){
        if(typeof this.#Event[type] == "undefined"){
             this.#Event[type] = [];
        }
        this.#Event[type].push(func);
    }
    /* 消息 */
    onGroupMessage(object) {
        if(typeof this.#Event.onGroupMessage == "undefined") return true;
        //群
        let group = object.data.sender.group;
        let msg = this.getMsgPlain(object.data.messageChain);
        let user = {id:object.data.sender.id,name:object.data.sender.memberName};

        let EventArr = this.#Event.onGroupMessage;
        EventArr.forEach(funcs=>funcs(group,user,msg));
        // RobotApiClass.recall(msg.id);//撤回消息
        // RobotApiClass.Banned(group.id,user.id,600);//禁言
        // RobotApiClass.SetMemberInfo(569211842,user.id,"你的名片被修改了!"+new Date().getTime());
        // RobotApiClass.sendGroupMsg(569211842, object.data.messageChain);
    }
    onChumMessage(object) {
        if(typeof this.#Event.onChumMessage == "undefined") return true;
        //私聊
        let msg = this.getMsgPlain(object.data.messageChain);
        let user = {id:object.data.sender.id,name:object.data.sender.memberName};

        let EventArr = this.#Event.onChumMessage;
        EventArr.forEach(funcs=>funcs(user,msg));
        // RobotApiClass.sendGroupMsg(569211842,user.name+" 好友私聊我了");
        
        // RobotApiClass.sendChumMsg(user.id,[RobotApiClass.text("你是憨憨"),RobotApiClass.image("http://c2cpicdw.qpic.cn/offpic_new/1294858802//1294858802-1413704395-903FDA8CD215ED8847EA03CCD7A8EE80/0?term=2")]);
    }
    onTempMessage(object){
        if(typeof this.#Event.onTempMessage == "undefined") return true;
        //临时私聊(会话)
        let msg = this.getMsgPlain(object.data.messageChain);
        let user = {id:object.data.sender.id,name:object.data.sender.memberName};

        let EventArr = this.#Event.onTempMessage;
        EventArr.forEach(funcs=>funcs(user,msg));
        // RobotApiClass.sendGroupMsg(569211842,user.name+" 向我发起了临时会话!");
        // RobotApiClass.GetGroupList(569211842,(code,list)=>{
        //     log(list);
        // });
    }
    getMsgPlain(MsgArr){
        // 解析msg信息!
        let msg = {
            id:null,
            time:null,
            image:[],
            text:''
        };
        MsgArr.forEach(v=>{
            if(v.type == "Source") {
                msg.id = v.id;
                msg.time = v.time;
            }
            if(v.type == "Plain"){
                msg.text += v.text;
            }
            if(v.type == "Face"){
                msg.text += `[${v.name}]`;
            }
            if(v.type == "Image"){
                msg.image.push(v.url);
            }
            if(v.type == "At"){
                msg.text += `@${v.target}`;
            }
        });
        return msg;
    }
    /* 事件 */
    /* 成员被踢出群 */
    onMemberLeaveEventKick(object){
        if(typeof this.#Event.onMemberLeaveEventKick == "undefined") return true;
        let user = {id:object.data.member.id,name:object.data.member.memberName};
        let operator = {id:object.data.operator.id,name:object.data.operator.memberName};
        let group = {id:object.data.member.group.id,name:object.data.member.group.name};

        let EventArr = this.#Event.onMemberLeaveEventKick;
        EventArr.forEach(funcs=>funcs(group,user,operator));
        // RobotApiClass.sendGroupMsg(group.id,`${user.name} 这个憨憨不守规矩,被${operator.name} 大大 请出群了!! 还是我 守规矩!`);
    }
    /* 成员主动退群 */
    onMemberLeaveEventQuit(object){
        if(typeof this.#Event.onMemberLeaveEventQuit == "undefined") return true;
        let user = {id:object.data.member.id,name:object.data.member.memberName};
        let group = {id:object.data.member.group.id,name:object.data.member.group.name};

        let EventArr = this.#Event.onMemberLeaveEventQuit;
        EventArr.forEach(funcs=>funcs(group,user));
        // RobotApiClass.sendGroupMsg(group.id,`${user.name} 这个憨憨自己觉得不如大家,退群了!`);
    }
    /* 新成员申请入群 */
    onMemberJoinRequestEvent(object){
        if(typeof this.#Event.onMemberJoinRequestEvent == "undefined") return true;
        let user = {id:object.data.fromId,name:object.data.nick,msg:object.data.message,eventId:object.data.eventId};
        let group = {id:object.data.groupId,name:object.data.groupName};

        let EventArr = this.#Event.onMemberJoinRequestEvent;
        EventArr.forEach(funcs=>funcs(group,user));
        // RobotApiClass.ProcessGroupOn(group.id,user.id,user.eventId,0,"因为你长得太丑!");
    }
    /* 新成员加入 */
    onMemberJoinEvent(object){
        if(typeof this.#Event.onMemberJoinEvent == "undefined") return true;
        let user = {id:object.data.member.id,name:object.data.member.memberName};
        let group = {id:object.data.member.group.id,name:object.data.member.group.name};

        let EventArr = this.#Event.onMemberJoinEvent;
        EventArr.forEach(funcs=>funcs(group,user));
        // RobotApiClass.sendGroupMsg(group.id,`@${user.name} 欢迎你加入这个大家庭!`);
    }
    /* 成员被禁言 */
    onMemberMuteEvent(object) {
        if(typeof this.#Event.onMemberMuteEvent == "undefined") return true;
        let user = {id:object.data.member.id,name:object.data.member.memberName};
        let group = {id:object.data.member.group.id,name:object.data.member.group.name};
        let muteTime = object.data.durationSeconds;//禁言秒数

        let EventArr = this.#Event.onMemberMuteEvent;
        EventArr.forEach(funcs=>funcs(group,user,muteTime));
        // log(muteTime);
    }
}



//游戏事件

class GameEvent {
    #Event = {};
    constructor() { }
    /* 注册事件 */
    regEvent(type,func){
        if(typeof this.#Event[type] == "undefined"){
             this.#Event[type] = [];
        }
        this.#Event[type].push(func);
    }
    /* ##玩家事件 */
    /* 玩家连接服务器 */
    onPreJoin(player) {
        if(typeof this.#Event.onPreJoin == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onPreJoin;
        EventArr.forEach(funcs=>{
            let funResult = funcs(player);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }
    /* 玩家进入游戏 */
    onJoin(player) {
        if(typeof this.#Event.onJoin == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onJoin;
        EventArr.forEach(funcs=>{
            let funResult = funcs(player);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
        // log(player.name + "进入游戏了!");
    }
    /* 玩家离开游戏 */
    onLeft(player) {
        if(typeof this.#Event.onLeft == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onLeft;
        EventArr.forEach(funcs=>{
            let funResult = funcs(player);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
        // log(player.name + "离开游戏了!");
    }
    /* 玩家重生 */
    onRespawn(player) {
        if(typeof this.#Event.onRespawn == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onRespawn;
        EventArr.forEach(funcs=>{
            let funResult = funcs(player);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }
    /* 玩家死亡 */
    onPlayerDie(player, source) {
        if(typeof this.#Event.onPlayerDie == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onPlayerDie;
        EventArr.forEach(funcs=>{
            let funResult = funcs(player,source);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }
    /* 玩家执行命令 */
    onPlayerCmd(player, cmd) {
        if(typeof this.#Event.onPlayerCmd == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onPlayerCmd;
        EventArr.forEach(funcs=>{
            let funResult = funcs(player,cmd);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }
    /* 玩家发送聊天 */
    onChat(player, msg) {
        if(typeof this.#Event.onChat == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onChat;
        EventArr.forEach(funcs=>{
            let funResult = funcs(player,msg);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }

    /* ##生物事件 */
    /* 生物死亡 */
    onMobDie(mob, source) {
        if(typeof this.#Event.onMobDie == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onMobDie;
        EventArr.forEach(funcs=>{
            let funResult = funcs(mob, source);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }
    /* 生物受伤 */
    onMobHurt(mob, source, damage) {
        if(typeof this.#Event.onMobHurt == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onMobHurt;
        EventArr.forEach(funcs=>{
            let funResult = funcs(mob, source, damage);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }
    /* npc执行命令 */
    onNpcCmd(npc, pl) {
        if(typeof this.#Event.onNpcCmd == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onNpcCmd;
        EventArr.forEach(funcs=>{
            let funResult = funcs(npc, pl);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }

    /* ##方块事件 */
    /* 命令方块执行命令 */
    onCmdBlockExecute(cmd, pos, isMinecart) {
        if(typeof this.#Event.onCmdBlockExecute == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onCmdBlockExecute;
        EventArr.forEach(funcs=>{
            let funResult = funcs(cmd, pos, isMinecart);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }

    /* ##其它事件 */
    /* 服务器启动完毕 */
    onServerStarted() {
        if(typeof this.#Event.onServerStarted == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onServerStarted;
        EventArr.forEach(funcs=>{
            let funResult = funcs();
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }
    /* 服务端执行后台命令 */
    onConsoleCmd(cmd) {
        if(typeof this.#Event.onConsoleCmd == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onConsoleCmd;
        EventArr.forEach(funcs=>{
            let funResult = funcs(cmd);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }
    /* 控制台产生命令输出 */
    onConsoleOutput(cmd) {
        if(typeof this.#Event.onConsoleOutput == "undefined") return true;
        let intercept = true;
        let EventArr = this.#Event.onConsoleOutput;
        EventArr.forEach(funcs=>{
            let funResult = funcs(cmd);
            if(typeof funResult != "undefined" && !funResult){
                intercept = false;
            }
        });
        return intercept;
    }
}

/* 机器人API */
class RobotApi {
    constructor() { }
    /* 群聊 */
    /* 发送群消息 */
    sendGroupMsg(group, msg) {
        let NewMsg;
        if(!Array.isArray(msg)){
            if(typeof msg != "object"){
                NewMsg = [this.text(msg)];
            }else{
                NewMsg = [msg];
            }
            
        }else{
            
            NewMsg = msg;
        }
        let out = {
            syncId: 123,
            command: "sendGroupMessage",
            subCommand: null,
            content: {
                sessionKey: websocketClass.sessionKey,
                target: group,
                messageChain:NewMsg
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }
    //发送格式
    text(msg){
        return {type:"Plain",text:msg};
    }
    image(url){
        return {type:"Image",url:url};
    }
    xml(xml){
        return {type:"Xml",xml:xml};
    }
    voice(url){
        return {type: "Voice",url: url};
    }
    at(qq){
        return {type:"At",target:qq,display:''};
    }
    atall(){
        return {type:"AtAll",target:0};
    }
    /* 私聊 */
    sendChumMsg(qq, msg) {
        let NewMsg;
        if(!Array.isArray(msg)){
            if(typeof msg != "object"){
                NewMsg = [this.text(msg)];
            }else{
                NewMsg = [msg];
            }
            
        }else{
            
            NewMsg = msg;
        }
        let out = {
            syncId: 123,
            command: "sendFriendMessage",
            subCommand: null,
            content: {
                sessionKey: websocketClass.sessionKey,
                target: qq,
                messageChain:NewMsg
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }
    /* 发送临时会话消息 */
    sendTempMsg(group,qq, msg) {
        let NewMsg;
        if(!Array.isArray(msg)){
            if(typeof msg != "object"){
                NewMsg = [this.text(msg)];
            }else{
                NewMsg = [msg];
            }
            
        }else{
            
            NewMsg = msg;
        }
        let out = {
            syncId: 123,
            command: "sendTempMessage",
            subCommand: null,
            content: {
                sessionKey: websocketClass.sessionKey,
                qq: qq,
                group:group,
                messageChain:NewMsg
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }

    /* 群管 */
    recall(id){
        //撤回消息
        let out = {
            syncId: 123,
            command: "recall",
            subCommand: null,
            content: {
                sessionKey: websocketClass.sessionKey,
                target: id
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }

    Banned(group,qq,time = 600){
        //禁言群成员
        let out = {
            syncId: 123,
            command: "mute",
            subCommand: null,
            content: {
                sessionKey: websocketClass.sessionKey,
                target: group,
                memberId:qq,
                time
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }

    RemoveBanned(group,qq){
        //解除禁言群成员
        let out = {
            syncId: 123,
            command: "unmute",
            subCommand: null,
            content: {
                sessionKey: websocketClass.sessionKey,
                target: group,
                memberId:qq
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }

    KickMembers(group,qq,msg = "您已被移出群聊"){
        //踢出群成员
        let out = {
            syncId: 123,
            command: "kick",
            subCommand: null,
            content: {
                sessionKey: websocketClass.sessionKey,
                target: group,
                memberId:qq,
                msg
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }

    BannedAll(group){
        //全体禁言
        let out = {
            syncId: 123,
            command: "muteAll",
            subCommand: null,
            content: {
                sessionKey: websocketClass.sessionKey,
                target: group
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }
    
    RemoveBannedAll(group){
        //解除群全体禁言
        let out = {
            syncId: 123,
            command: "unmuteAll",
            subCommand: null,
            content: {
                sessionKey: websocketClass.sessionKey,
                target: group
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }

    SetMemberInfo(group,qq,name,specialTitle = null){
        //修改群员设置
        let out = {
            syncId: 123,
            command: "memberInfo",
            subCommand: "update",
            content: {
                sessionKey: websocketClass.sessionKey,
                target: group,
                memberId:qq,
                info: {
                    name:name,
                    specialTitle:specialTitle
                }
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }

    GetMemberInfo(group,qq,func){
        //获取群员设置
        let out = `http://${ROBOTCONFIG.get("host")}:${ROBOTCONFIG.get("port")}/memberInfo?sessionKey=${websocketClass.sessionKey}&target=${group}&memberId=${qq}`;
        network.httpGet(out,(status,result)=>{
            let isJson = websocketClass.isJSON(result);
            if(isJson){
                result = JSON.parse(result);
            }
            func(status,result);
        });
    }

    ProcessGroupOn(group,qq,eveid,type = 0,msg = ''){
        //处理成员入群 type   0同意 1拒绝 2忽略 3拒绝入群并添加黑名单，不再接收该用户的入群申请 4忽略入群并添加黑名单，不再接收该用户的入群申请
        let out = {
            syncId: 123,
            command: "resp_memberJoinRequestEvent",
            subCommand: null,
            content: {
                sessionKey: websocketClass.sessionKey,
                eventId:eveid,
                groupId: group,
                fromId:qq,
                operate:type,
                message:msg
            }
        };
        websocketClass.sendMsg(JSON.stringify(out));
    }

    GetGroupList(group,func){
        //获取群成员列表
        let out = `http://${ROBOTCONFIG.get("host")}:${ROBOTCONFIG.get("port")}/memberList?sessionKey=${websocketClass.sessionKey}&target=${group}`;
        network.httpGet(out,(status,result)=>{
            let isJson = websocketClass.isJSON(result);
            if(isJson){
                result = JSON.parse(result).data;
            }
            func(status,result);
        });
    }
    
    /* 好友 */
}

/* 自定义封装的 */
class Yoyo{
    constructor(){}
    JsonConfig(path,jsondata = "{}"){//配置文件
        let jsonConfig = PluginsClass.path+"\\"+path;
        return new JsonConfigFile(jsonConfig,jsondata);
    }

    IniConfig(path,inidata = ""){//配置文件
        let jsonConfig = PluginsClass.path+"\\"+path;
        return new IniConfigFile(jsonConfig,jsondata);
    }

    database(path){//键对值 数据库
        let jsonConfig = PluginsClass.path+"\\"+path;
        return new new KVDatabase(jsonConfig);
    }
}

/* 插件扩展 */
class Plugins{
    path = ".\\plugins\\Yoyo\\LXLRobot\\plugins";
    list = [];
    constructor(){
        if(!this.inFile(this.path)){
            File.createDir(this.path);
        }
    }
    inFile(path){
        return File.exists(path)
    }

    loadPluginsAll(){//加载扩展
        log("=========   LXLRobot Script Plugin Load   =========");
        let fileArr = File.getFilesList(this.path).filter(v=>/.+\.js$/.test(v));
        fileArr.forEach(plugins=>{
            if(!this.list.includes(plugins)){
                this.list.push(plugins);
            }
            try {
                require(`${this.path}\\${plugins}`);
                logger.info("load "+plugins);
            } catch (error) {
                logger.error("Error "+plugins);
            }
        });
    }
    
    listen(type,func){//注册监听
        if(typeof RobotEventClass[type] == "function"){
            RobotEventClass.regEvent(type,func);//注入事件
            return true;
        }else if(typeof GameEventClass[type] == "function"){
            GameEventClass.regEvent(type,func);//注入事件
            return true;
        }else{
            return false;
        }
    }
}

/* 其它封装 */
const YoyoClass = new Yoyo();
/* 游戏事件 */
const GameEventClass = new GameEvent();
/* 机器人API */
const RobotApiClass = new RobotApi();
/* 初始化扩展(此时并未加载|等key获取成功才加载)*/
const PluginsClass = new Plugins();
/* 开启websocket服务 */
const websocketClass = new websocket();
/* 机器人事件 */
const RobotEventClass = new RobotEvent();


/* 注册命令 */


/* 设置游戏事件绑定监听 */
/* ##玩家事件 */
/* 玩家连接服务器 */
mc.listen("onPreJoin", (player) => { return GameEventClass.onPreJoin(player) });
/* 玩家进入游戏 */
mc.listen("onJoin", (player) => { return GameEventClass.onJoin(player) });
/* 玩家离开游戏 */
mc.listen("onLeft", (player) => { return GameEventClass.onLeft(player) });
/* 玩家重生 */
mc.listen("onRespawn", (player) => { return GameEventClass.onRespawn(player) });
/* 玩家死亡 */
mc.listen("onPlayerDie", (player, source) => { return GameEventClass.onPlayerDie(player, source) });
/* 玩家执行命令 */
mc.listen("onPlayerCmd", (player, cmd) => { return GameEventClass.onPlayerCmd(player, cmd) });
/* 玩家发送聊天 */
mc.listen("onChat", (player, msg) => { return GameEventClass.onChat(player, msg) });

/* ##生物事件 */
/* 生物死亡 */
mc.listen("onMobDie", (mob, source) => { return GameEventClass.onMobDie(mob, source) });
/* 生物受伤 */
mc.listen("onMobHurt", (mob, source, damage) => { return GameEventClass.onMobHurt(mob, source, damage) });
/* npc执行命令 */
mc.listen("onNpcCmd", (npc, pl) => { return GameEventClass.onNpcCmd(npc, pl) });

/* ##方块事件 */
/* 命令方块执行命令 */
mc.listen("onCmdBlockExecute", (cmd, pos, isMinecart) => { return GameEventClass.onCmdBlockExecute(cmd, pos, isMinecart) });

/* ##其它事件 */
/* 服务端执行后台命令 */
mc.listen("onConsoleCmd", (cmd) => { return GameEventClass.onConsoleCmd(cmd) });
/* 控制台产生命令输出 */
mc.listen("onConsoleOutput", (cmd) => { return GameEventClass.onConsoleOutput(cmd) });
/* 服务器启动完毕 */
mc.listen("onServerStarted", () => {return GameEventClass.onServerStarted() });

log(`
██╗     ██╗  ██╗██╗     ██████╗  ██████╗ ██████╗  ██████╗ ████████╗
██║     ╚██╗██╔╝██║     ██╔══██╗██╔═══██╗██╔══██╗██╔═══██╗╚══██╔══╝
██║      ╚███╔╝ ██║     ██████╔╝██║   ██║██████╔╝██║   ██║   ██║   
██║      ██╔██╗ ██║     ██╔══██╗██║   ██║██╔══██╗██║   ██║   ██║   
███████╗██╔╝ ██╗███████╗██║  ██║╚██████╔╝██████╔╝╚██████╔╝   ██║   
╚══════╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝ ╚═════╝ ╚═════╝  ╚═════╝    ╚═╝   
                                                                   
`);
logger.info("version: v0.0.4 author:Yoyo QQ:1294858802");